<template>
  <div class="mybox">
    <div class="top_box">
      <div class="item_box">
        <div class="title">垃圾回收站数量</div>
        <div class="btm_value">
          <div class="value">{{ onebox.field_value.replace(/\D/g, '') }}</div>
          <div class="unit">个</div>
        </div>
      </div>
      <div class="item_box">
        <div class="title">垃圾回收车数量</div>
        <div class="btm_value">
          <div class="value">{{ twobox.field_value.replace(/\D/g, '') }}</div>
          <div class="unit">辆</div>
        </div>
      </div>
      <div class="item_box box">
        <div class="title">月度垃圾处理总量</div>
        <div class="btm_value">
          <div class="value">{{ threebox.field_value.replace(/\D/g, '') }}</div>
          <div class="unit">吨</div>
        </div>
      </div>
    </div>
    <div class="mychart">
      <div class="chart" ref="main"></div>
    </div>
  </div>
</template>
<script>
// import chart from './chart.vue'
import { getAction, postAction } from '@/api/manage'
import * as echarts from 'echarts'
export default {
  name: '',
  data () {
    return {
      onebox: {},
      twobox: {},
      threebox: {},
      chartData: {
        xData: [],
        data: [],
        name: ['垃圾处理量'],
        unit: '万吨',
        title: '垃圾处理量'
      }
    }
  },
  // components: {
  //   chart
  // },
  mounted () {
    this.initData()
  },
  methods: {
    initData () {
      getAction('/topic/data/listAllBySql/dy_dp_csgl_zxgz_gk', { type: '市容环境' }).then(res => {
        if (res.success) {
          this.onebox = res.result[0]
          this.twobox = res.result[1]
          this.threebox = res.result[2]
        }
      })
      getAction('/topic/data/listAllBySql/dy_dp_csgl_zxgz_month', { type: '市容环境' }).then(res => {
        if (res.success) {
          this.chartData.xData = []
          this.chartData.data = []
          res.result.map(item => {
            this.chartData.xData.push(item.year)
            this.chartData.data.push(item.amount)
          })
          this.getChart(this.chartData)
        }
      })
    },
    getChart (val) {
      let myChart = echarts.init(this.$refs.main)
      let option

      option = {
        grid: {
          top: '20%',
          left: '1%',
          right: '2%',
          bottom: '5%',
          containLabel: true
        },
        legend: {
          padding: [10, 0],
          orient: 'horizontal',
          right: 60,
          itemGap: 12,
          data: val.name,
          textStyle: {
            color: '#f9f9f9',
            borderColor: '#fff',
            fontSize: 12
          }
        },
        xAxis: [{
          nameGap: 5,
          type: 'category',
          axisLine: {
            show: true,
            lineStyle: {
              color: '#999'
            }
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#FFFFFF',
              fontSize: 10
            }
          },
          axisTick: {
            show: false
          },
          data: val.xData
        }],
        yAxis: [{
          name: `单位：${val.unit}`,
          type: 'value',
          nameTextStyle: {
            color: '#FFFFFF',
            fontSize: 12
          },
          min: 0,
          splitNumber: 5,
          splitLine: {
            show: true,
            lineStyle: {
              color: '#0a3256'
            }
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            textStyle: {
              color: '#FFFFFF',
              fontSize: 10
            }
          },
          axisTick: {
            show: false
          }
        }],
        tooltip: {
          trigger: 'axis'
        },
        series: [{
          name: val.name,
          type: 'line',
          symbolSize: 8, // 设置数据点的大小为10
          symbol: 'circle', // 设置数据点的形状为圆圈
          lineStyle: {
            color: '#55D297', // 线的颜色
            width: 2, // 线的宽度
            type: 'solid' // 线的类型，默认为实线
          },
          itemStyle: {
            color: '#55D297',
            borderColor: '#fff',
            borderWidth: 2 // 点的边框宽度
          },
          areaStyle: {
            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
              offset: 0,
              color: 'rgba(85, 210, 151, 1)'
            },
            {
              offset: 1,
              color: 'rgba(85, 210, 151, 0)'
            }
            ])
          },
          data: val.data
        }
        ]
      }

      option && myChart.setOption(option)
    }
  }
}
</script>
<style lang="scss" scoped>
.mybox {
  .top_box {
    display: flex;
    justify-content: space-between;

    .item_box {
      width: 132px;
      height: 53px;
      background: url('./img/11.png');

      .title {
        font-family: Source Han Sans CN;
        font-weight: bold;
        font-size: 18px;
        color: #F1F1F1;
        text-align: center;
        margin-bottom: 4px;
      }

      .btm_value {
        display: flex;
        justify-content: center;

        .value {
          font-family: Microsoft YaHei UI;
          font-weight: bold;
          font-size: 20px;
          color: #FFDE00;
        }

        .unit {
          font-family: Microsoft YaHei UI;
          font-weight: 400;
          font-size: 14px;
          color: #FFFFFF;
          margin-top: 5px;
        }
      }
    }

    .box {
      width: 150px;
      height: 53px;
      background: url('./img/11.png')no-repeat center center;
      background-size: 100% 100%;
    }
  }

  .mychart {
    width: 100%;
    height: 300px;

    .chart {
      width: 100%;
      height: 160px;
    }
  }
}
</style>
